
/* 
   MUNILIST     List various useful infromations from list 
                of processed files.
   Copyright (C) 1997-x  Filip Hroch, Masaryk University, Brno, CZ

   This is a wrapper from UNIX-like environment with std. inputs,
   environment and command line options to the Fortran file input
   plain world.

   $Id$

*/


#include "gexe.h"
#include "cwrap.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

void help();

int main(int argc,char *argv[])
{
  char *namsci = NULL;
  char outlst = ' ';
  int stdinput = 0;
  int col = 4;
  int quiet = 0;
  double min0, per = -1.0;
  double alpha = -999.9, delta = -99.9;
  double longit = -999.9, lat = -99.9;
  double tol = 10.0;


  fprintf(stdout,"MUNILIST Version 1.4, Copyright (C) 1997-7 F.Hroch, Masaryk University, Brno,CZ\n\n");

  if( argc == 1 ) {
    help();
    return(0);
  }   

  for( i = 1; i < argc; i++) {

    /* dir file */
    if( (j = strstr(argv[i],"@")) != NULL ) {
      if( strlen(argv[i]) == 1 )
	stdinput = 1;
      else 
	namsci = j + strlen("@");
    }

    /* column */
    else if( (j = strstr(argv[i],"col=")) != NULL && 
	     (sscanf(j+strlen("col="),"%d",&col) == 1) )
      ;

    /* full output */
    else if( strcmp(argv[i],"-of") == 0 )
      outlst = 'f';

    /* intensities on output */
    else if( strcmp(argv[i],"-oi") == 0 )
      outlst = 'i';
    
    /* photometric elements */
    else if( (j = strstr(argv[i],"ele=")) != NULL && 
	     (sscanf(j+strlen("ele="),"%f%*c%f",&min0,&per) == 2) )
      ;

    /* equatorial coordinates */
    else if( (j = strstr(argv[i],"coo=")) != NULL && 
	     (sscanf(j+strlen("coo="),"%f%*c%f",&alpha,&delta) == 2) )
      ;

    /* geographics coordinates */
    else if( (j = strstr(argv[i],"geo=")) != NULL && 
	     (sscanf(j+strlen("geo="),"%f%*c%f",&longit,&lat) == 2) )
      ;
    
    /* radius of tolerance */
    else if( (j = strstr(argv[i],"tol=")) != NULL && 
	     (sscanf(j+strlen("tol="),"%f",&tol) == 1) )
      ;
    


    /* suffix */
    else if( (j = strstr(argv[i],"suf=")) != NULL )
      suf = j + strlen("suf=");
	     

    /* quite */
    else if( strcmp(argv[i],"-q") == 0 )
      quiet = 1

    
    /* license */
    else if( strcmp(argv[i],"-L") == 0 ) {
      licence();
      return(0);
    }

    /* help */
    else if( strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") ==0 ){
      help();
      return(0);
    }

    /* one or two numers only => #line or coordinates */
    else {
      
      

    }

  }

}

void help()
{
  printf("%s\n\n%s\n%s\n",
	 "MUNILIST   List of various useful quantities from set of processed files"
	 "Usage: munilist [@dirfile] [col=column] [-of] [line_var] [line_comp1] ..",
	 "               [ele=min0,period] [suf=suffix] [image1]..",
	 "@dirfile= file with name(s) of stars catalogue(s), no wildcards *,?",
	 "          (for only '@', read catalogue(s) name(s) from standart input)",
	 "col= column for listing (4 = Aperture 1, default)",
	 "-of= full output list (default short output list)",
	 "-oi= like -of, but intensities (no magnitudes) on output",
	 "     (with coo=, geo= include azimutal coordinates and airmass in list)",
	 "coo= alpha,delta (degrees) of variable  stars for heliocentric correction",
	 "ele= epoch, period of variable stars for phase output",
	 "geo= geographic coordinates (degrees, +east,+north) of site (for -oi)",
	 "suf= suffix of listing files (default = 'MAT')",
	 "tol= upper limit for coordinate search (default=10)",
	 "line_var  line_comp1...= line with stars",
	 "xcoo1,ycoo1 xcoo2,ycoo2 ...= x,y coordinates of stars",
	 "image1...= name(s) of simple image(s) to list (.fits)",
	 "-q = quiet",
	 "\t-h\t give this help",
	 "\t-L\t display software license");
}
